import { reqCategoryList, reqGetBannerList, reqFloorList } from "@/api"

// home仓库的小模块
export default {
  actions: {
    async categoryList ({ commit }) {
      // 向远程服务器发送请求
      const result = await reqCategoryList();
      result.data.splice(-2);
      // console.log(result);
      if (result.code >= 200 && result.code < 300) {
        commit('CATEGORYLIST', result.data)
      }
    },
    async reqGetBannerList ({ commit }) {
      // 向mock请求数据
      const result = await reqGetBannerList();
      // console.log(result);
      if (result.code >= 200 && result.code < 300) {
        commit('BANNERLIST', result.data)
      }
    },
    async reqFloorList ({ commit }) {
      // 向mock请求数据
      const result = await reqFloorList()
      // console.log(result);
      if (result.code >= 200 && result.code < 300) {
        commit('FLOORLIST', result.data)
      }
    }
  },
  mutations: {
    CATEGORYLIST (state, categoryList) {
      state.categoryList = categoryList;
    },
    BANNERLIST (state, bannerList) {
      state.bannerList = bannerList;
    },
    FLOORLIST (state, floorList) {
      state.floorList = floorList;
    }
  },
  state: {
    // state内的数据类型根据接口返回值初始化
    categoryList: [],
    // 轮播图的数据
    bannerList: [],
    floorList: []
  },
  getters: {}
}
